﻿using System;

namespace PRO.Config
{

	
	/// <summary>
    /// 基本设置类
	/// </summary>
	public class BaseConfigs
	{

        private static object lockHelper = new object();

        private static System.Timers.Timer baseConfigTimer = new System.Timers.Timer(15000);

        private static BaseConfigInfo m_configinfo;

		/// <summary>
        /// 静态构造函数初始化相应实例和定时器
		/// </summary>
        static BaseConfigs()
        {
            m_configinfo = BaseConfigFileManager.LoadConfig();           
        }

        private static void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            ResetConfig();
        }


        /// <summary>
        /// 重设配置类实例
        /// </summary>
        public static void ResetConfig()
        {
            m_configinfo = BaseConfigFileManager.LoadRealConfig();
        }

		public static BaseConfigInfo GetBaseConfig()
		{
            return m_configinfo;
		}

		/// <summary>
		/// 返回数据库连接串
		/// </summary>
		public static string GetDBConnectString
		{
			get
			{
				return GetBaseConfig().Dbconnectstring;
			}
		}


		/// <summary>
		/// 返回表前缀
		/// </summary>
        public static string GetTablePrefix
        {
            get
            {
                return GetBaseConfig().Tableprefix;
            }
        }

        public static string GetForumpath
        {
            get
            {
                return GetBaseConfig().Forumpath;
            }
        }
        /// <summary>
        /// 邮件发送服务器
        /// </summary>
        public static string EmailHost
        {
            get
            {
                return GetBaseConfig().EmailHost;
            }
        }
        /// <summary>
        /// 邮件发送服务器端口
        /// </summary>
        public static int EmailPort
        {
            get
            {
                return GetBaseConfig().EmailPort;
            }
        }
        /// <summary>
        /// 发送邮件是否启用SSL
        /// </summary>
        public static bool EnableSSL
        {
            get
            {
                return GetBaseConfig().EnableSSL;
            }
        }
        /// <summary>
        /// 发送邮件账号
        /// </summary>
        public static string EmailAccount
        {
            get
            {
                return GetBaseConfig().EmailAccount;
            }
        }
        /// <summary>
        /// 发送邮件账号的密码
        /// </summary>
        public static string EmailPwd
        {
            get
            {
                return GetBaseConfig().EmailPwd;
            }
        }
        /// <summary>
        /// DEC加密向量
        /// </summary>
        public static string DEC_KEY
        {
            get
            {
                return GetBaseConfig().DEC_KEY;
            }
        }



        public static string Title
        {
            get
            {
                return GetBaseConfig().Title;
            }
        }

        public static string Keywords
        {
            get
            {
                return GetBaseConfig().Keywords;
            }
        }
        public static string Description
        {
            get
            {
                return GetBaseConfig().Description;
            }
        }
        public static string Transport
        {
            get
            {
                return GetBaseConfig().Transport;
            }
        }

        public static string Refunded_OR_Exchanged
        {
            get
            {
                return GetBaseConfig().Refunded_OR_Exchanged;
            }
        }

        /// <summary>
        /// 保存配置实例
        /// </summary>
        /// <param name="baseconfiginfo"></param>
        /// <returns></returns>
        public static bool SaveConfig(BaseConfigInfo baseconfiginfo)
        {
            BaseConfigFileManager acfm = new BaseConfigFileManager();
            BaseConfigFileManager.ConfigInfo = baseconfiginfo;
            return acfm.SaveConfig();
        }
		
	}
}
